import settings from '@/settings.js'

export const myRequest = (options)=>{
  // 过滤辣鸡微信undefined还传参
  const data = {}
  Object.keys(options.data).forEach((key)=>{
    if(options.data[key] !== undefined){
      data[key] = options.data[key]
    }
  })
	return new Promise((resolve, reject)=>{
		uni.request({
			url:settings.base_url + "/" + settings.prefix + options.url,
			method: options.method || 'GET',
			data: data || {},
			success: (res)=>{
				if(res.statusCode !== 200) {
					uni.showToast({
            icon:"error",
						title: res.statusCode + '拉取数据失败'
					})
          reject({
            message:res.statusCode + '拉取数据失败'
          })
          return
				}
				resolve(res.data)
			},
			fail: (err)=>{
        console.log('err',err)
				uni.showToast({
          icon:"error",
					title: err.errMsg
				})
				reject(err)
			}
		})
	})
}